package code.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBUtil {
	private static final String driverClass="com.mysql.jdbc.Driver";

	private static final String jdbcUrl="jdbc:mysql://118.192.1.80:3306/location";

	private static final String user="root";

	private static final String password="xPt9iO3b";




	private DBUtil(){
		
	}


    public static Connection getConn(){
		return getConn(false);
    }
    

    public static Connection getConn(boolean autoCommit) {
    	Connection con=null;
    	try {
			Class.forName(driverClass) ;
			con = DriverManager.getConnection(jdbcUrl , user, password);
			con.setAutoCommit(autoCommit); 
    	} catch (Exception e) {
			System.out.println("DBUtil-->getConn");
		}
		return con;
    }    
    
    public static void closeConn(Connection conn){
    	if(conn!=null){
    		try{
    			conn.close();
    		}catch (Exception e){
    			System.out.println("DBUtil-->closeConn");
    		}
    		
    	}
    }
    
    
    public static void commitConn(Connection conn){
    	if(conn!=null){
    		try{
    			conn.commit();
    		}catch (Exception e){
    			System.out.println("DBUtil-->commitConn");
    		}
    		
    	}
    }
    
    public static void rollbackConn(Connection conn){
    	if(conn!=null){
    		try{
    			conn.rollback();
    		}catch (Exception e){
    			System.out.println("DBUtil-->rollbackConn");
    		}
    		
    	}
    }
}
